package com.burst.reptile.modular.system.service.impl;

import com.burst.reptile.common.constant.UserConstants;
import com.burst.reptile.common.utils.ToolUtil;
import com.burst.reptile.modular.system.entity.SysDictType;
import com.burst.reptile.modular.system.mapper.SysDictTypeMapper;
import com.burst.reptile.modular.system.service.ISysDictTypeService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

import org.springframework.stereotype.Service;

/**
 * <p>
 * 字典类型表 服务实现类
 * </p>
 *
 * @author wujin
 * @since 2020-05-22
 */
@Service
public class SysDictTypeServiceImpl extends ServiceImpl<SysDictTypeMapper, SysDictType> implements ISysDictTypeService {

	@Override
	public Page<SysDictType> selectPageDictTypeList(Page<SysDictType> page, SysDictType dictType) {
		return this.baseMapper.selectPageDictTypeList(page, dictType);
	}

	@Override
	public List<SysDictType> selectDictTypeList(SysDictType dictType) {
		return this.baseMapper.selectDictTypeList(dictType);
	}

	@Override
	public String checkDictTypeUnique(SysDictType dict) {
		Long dictId = ToolUtil.isEmpty(dict.getDictId()) ? -1L : dict.getDictId();
		SysDictType dictType = this.baseMapper.selectOne(new QueryWrapper<SysDictType>().eq("dict_type", dict.getDictType()));
		if (ToolUtil.isNotEmpty(dictType) && dictType.getDictId().longValue() != dictId.longValue()) {
			return UserConstants.NOT_UNIQUE;
		}
		return UserConstants.UNIQUE;
	}

	@Override
	public int insertDictType(SysDictType dict) {
		return this.baseMapper.insert(dict);
	}

	@Override
	public int updateDictType(SysDictType dictType) {
		return this.baseMapper.updateById(dictType);
	}

	@Override
	public int deleteDictTypeByIds(Long[] dictIds) {
		return this.baseMapper.deleteBatchIds(Arrays.asList(dictIds));
	}

}
